var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNo:1,
    pageSize:10,
    projectList:[]
  },
  godetail(e){
    let orderId=e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/projectDetails/projectDetails?orderId='+orderId,
    })
  },
// 店长
getShopownerFinishProjectPage(){
  let t=this
  wx.request({
    url: app.globalData.Interfaceurl + 'getShopownerFinishProjectPage',
    method: "post",
    header: {
      "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
    },
    data: {
      userId: t.data.id,
      pageSize:t.data.pageSize,
      pageNo:t.data.pageNo,
    },
    success: res => {
      wx.hideLoading();
      console.log(res)

      let projectList = t.data.projectList
      
      if (t.data.pageNo == 1) {
        projectList = res.data.page.list
      } else {
        projectList.push(...res.data.page.list)
      }
      t.setData({
        projectList: projectList,
        projectlast: res.data.page.last
      })
    
    },
    fail: err => {
      wx.showToast({
        title: '请求失败',
        duration: 2500, //持续的时间
            icon: 'none', //图标
      })
    }
  })
},
// 岩板砖家
getSuperviseFinishProjectPage(){
  let t=this
  wx.request({
    url: app.globalData.Interfaceurl + 'getSuperviseFinishProjectPage',
    method: "post",
    header: {
      "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
    },
    data: {
      userId: t.data.id,
      pageSize:t.data.pageSize,
      pageNo:t.data.pageNo,
    },
    success: res => {
      wx.hideLoading();
      console.log(res)

      let projectList = t.data.projectList
      
      if (t.data.pageNo == 1) {
        projectList = res.data.page.list
      } else {
        projectList.push(...res.data.page.list)
      }
      t.setData({
        projectList: projectList,
        projectlast: res.data.page.last
      })
    
    },
    fail: err => {
      wx.showToast({
        title: '请求失败',
        duration: 2500, //持续的时间
        icon: 'none', //图标
      })
    }
  })
},
// 设计师
getDesignerFinishProjectPage(){
  let t=this
  wx.request({
    url: app.globalData.Interfaceurl + 'getDesignerFinishProjectPage',
    method: "post",
    header: {
      "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
    },
    data: {
      userId: t.data.id,
      pageSize:t.data.pageSize,
      pageNo:t.data.pageNo,
    },
    success: res => {
      wx.hideLoading();
      console.log(res)

      let projectList = t.data.projectList
      
      if (t.data.pageNo == 1) {
        projectList = res.data.page.list
      } else {
        projectList.push(...res.data.page.list)
      }
      t.setData({
        projectList: projectList,
        projectlast: res.data.page.last
      })
    
    },
    fail: err => {
      wx.showToast({
        title: '请求失败',
        duration: 2500, //持续的时间
        icon: 'none', //图标
      })
    }
  })
},
// 瓦工
getBricklayFinishProjectPage(){
  let t=this
  wx.request({
    url: app.globalData.Interfaceurl + 'getBricklayFinishProjectPage',
    method: "post",
    header: {
      "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
    },
    data: {
      userId: t.data.id,
      pageSize:t.data.pageSize,
      pageNo:t.data.pageNo,
    },
    success: res => {
      wx.hideLoading();
      console.log(res)

      let projectList = t.data.projectList
      
      if (t.data.pageNo == 1) {
        projectList = res.data.page.list
      } else {
        projectList.push(...res.data.page.list)
      }
      t.setData({
        projectList: projectList,
        projectlast: res.data.page.last
      })
    
    },
    fail: err => {
      wx.showToast({
        title: '请求失败',
        duration: 2500, //持续的时间
        icon: 'none', //图标
      })
    }
  })
},





  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  this.setData({
    typeIndex:options.type,
    id:options.id,
    people:JSON.parse(options.people),
    Imageurl:app.globalData.Imageurl
  })
  let typeIndex=this.data.typeIndex

  if(typeIndex==0){
      this.getShopownerFinishProjectPage()
  }else if(typeIndex==1){
this.getSuperviseFinishProjectPage()
  }else if(typeIndex==2){
    this.getDesignerFinishProjectPage()
  }else{
    this.getBricklayFinishProjectPage()
  }
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    if (this.data.pageNo >= this.data.projectlast) {
      return
    }
    this.setData({
      pageNo: this.data.pageNo + 1
    })
    if(typeIndex==0){
      this.getShopownerFinishProjectPage()
  }else if(typeIndex==1){
this.getSuperviseFinishProjectPage()
  }else if(typeIndex==2){
    this.getDesignerFinishProjectPage()
  }else{
    this.getBricklayFinishProjectPage()
  }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },



  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})